﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>用户中心</title>
	<link rel="stylesheet" href="css/bootstrap.min.css">
	<script src="js/jquery/jquery.min.js"></script>
	<script src="js/jquery.validation/1.14.0/jquery.validate.min.js"></script>
	<script src="js/jquery.validation/1.14.0/messages_zh.min.js"></script>
	<style>
		input.error{
			border: 1px solid #E6594E;
		}
	</style>
</head>
<body>
    <div class="container">
	
		<form id="addUserForm">
		  <br/>
		  <div class="form-group">
			<label for="username">学生姓名：</label>
			<input type="text" class="form-control" id="name" name="name" placeholder="输入姓名">
		  </div>
		  <div class="form-group">
			<label for="userage">学生性别：</label>
			<input type="text" class="form-control" id="sex" name="sex" placeholder="输入性别">
		  </div>
		  <div class="form-group">
			<label for="userphone">学生手机：</label>
			<input type="text" class="form-control" id="phone" name="phone" placeholder="输入手机">
		  </div>
		  <div class="form-group">
			<label for="useremail">学生邮箱：</label>
			<input type="text" class="form-control" id="email" name="email" placeholder="输入邮箱">
		  </div>
		  <div class="form-group">
			<label for="useremail">学生生日：</label>
			<input type="text" class="form-control" id="birthday" name="birthday" placeholder="输入生日">
		  </div>
		  <div class="form-group">
		  <button type="button" id="saveBtn" class="btn btn-success">提交</button>
		  <button type="button" id="cancelBtn" class="btn btn-default">取消</button>
		  </div>
		</form>
    </div>

		<script>
			var addUser = function(){
				if(!check().form()){ 
					return;  
				}
				$.ajax({
					   type: "POST",
					   dataType: "json",
					   url: "/student/addStudent",
					   data: {
							"name": $("#name").val(),
							"sex":$("#sex").val(),
							"phone":$("#phone").val(),
							"email":$("#email").val(),
							"birthday":$("#birthday").val()
					   },
					   success: function(msg){
							//alert(msg);
							$('#cancelBtn').click();			
					   }
				});
			}
			
			$('#saveBtn').on('click', function(){
				addUser();
			});
			
			$('#cancelBtn').on('click', function(){
				var index = parent.layer.getFrameIndex(window.name);
				parent.getUserPageList();
				parent.layer.close(index);
			});

			
			//校验字段是否正确 
            function check(){ 
                /*返回一个validate对象，这个对象有一个form方法，返回的是是否通过验证*/ 
                return $("#addUserForm").validate({ 
                            rules:{ 
                                name:{ 
                                    required:true
                                },
                                sex:{ 
                                    required:true                                   
                                },
                                phone:{ 
                                    required:true                                   
                                },
                                email:{ 
                                    required:true                                   
                                },
                                birthday:{ 
                                    required:true                                   
                                }
                            }, 
                            messages:{ 
                                name:{ 
                                    required:""
                                },
                                sex:{ 
                                    required:""                                
                                },
                                phone:{ 
                                    required:""                                
                                },
                                email:{ 
                                    required:""                                
                                },
                                birthday:{ 
                                    required:""                                
                                }
                            }     
                        }); 
            } 
			
		</script> 	
</body>
</html>